﻿using System;
using System.Web.Mvc;
using AgileBoard.Domain;
using AgileBoard.Dtos;
using AgileBoard.Dtos.Mappers;
using AgileBoard.Web.Controllers.Util;

namespace AgileBoard.Web.Controllers
{
    public class FeelingsController : BaseController
    {
        public ActionResult Update(FeelingsDTO Json)
        {
            var rdto = new ResultDTO();
            ManagerFactory.FeelingManager.Update(FeelingsDTOMapper.MapFromDTO(Json));

            rdto.Result = true;
            rdto.Message = "Success";

            return this.Json(rdto);
        }

        public ActionResult Add(FeelingsDTO Json)
        {
            var rdto = new ResultDTO();
            Feelings Feeling = FeelingsDTOMapper.MapFromDTO(Json);
            Feeling.CreateTime = DateTime.Now;
            //Convert date from UTC to Local time
            Feeling.Date = TimeZone.CurrentTimeZone.ToLocalTime(Feeling.Date);

            try
            {
                Feeling = ManagerFactory.FeelingManager.Update(Feeling);
                rdto.Result = true;
                rdto.Message = "Success";
                rdto.Data = FeelingsDTOMapper.MapToDTO(Feeling).ToExtJsJson();
            }
            catch (Exception e)
            {
                rdto.Message = e.Message;
                rdto.Result = false;
            }

            return this.Json(rdto);
        }
    }
}